package com.hmkx.solr.funtion;

import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.queries.function.docvalues.FloatDocValues;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class FunctionValueSource extends ValueSource {
    final static Logger log= LoggerFactory.getLogger(FunctionValueSource.class);
    private  List<ValueSource>  valueSources;

    public FunctionValueSource(List<ValueSource> source) {
        this.valueSources=source;
    }

    @Override
    public FunctionValues getValues(Map map, final LeafReaderContext leafReaderContext) throws IOException {
        final FunctionValues y=this.valueSources.get(0).getValues(map,leafReaderContext);
        final FunctionValues m=this.valueSources.get(1).getValues(map,leafReaderContext);
        return new FloatDocValues(this) {
            @Override
            public float floatVal(int docId) {
                String title = y.strVal(docId);
                String des =m.strVal(docId);
                //这里加入你的逻辑计算


                return 2l;
            }
        };
    }

    @Override
    public boolean equals(Object o) {
        return false;
    }

    @Override
    public int hashCode() {
        return 0;
    }

    @Override
    public String description() {
        return null;
    }
}
